From: Jay Belanger Date: Sat, 7 Jul 2007 04:13:49 +0000 (+0000) Subject: (math-read-number): Replace number by variable. X-Git-Tag: archive/raspbian/1%29.2+1-2+rpi1~1^2~421^2~18065 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https:/www.github.com/%22bookmarks:///%22http:/www.example.com/cgi/%22https:/www.github.com/%22bookmarks:/?a=commitdiff_plain;h=9e8a1e16ab92e32031861824a8dc25fa4cc748c8;p=emacs.git (math-read-number): Replace number by variable. (math-read-number-simple): Properly parse small integers. --- diff --git a/lisp/calc/calc.el b/lisp/calc/calc.el index d81c1070b9f..922a7c8d7f8 100644 --- a/lisp/calc/calc.el +++ b/lisp/calc/calc.el @@ -3401,6 +3401,7 @@ largest Emacs integer.") ;;; Parse a simple number in string form. [N X] [Public] (defun math-read-number (s) + "Convert the string S into a Calc number." (math-normalize (cond @@ -3411,7 +3412,7 @@ largest Emacs integer.") (> (length digs) 1) (eq (aref digs 0) ?0)) (math-read-number (concat "8#" digs)) - (if (<= (length digs) 6) + (if (<= (length digs) (* 2 math-bignum-digit-length)) (string-to-number digs) (cons 'bigpos (math-read-bignum digs)))))) @@ -3459,13 +3460,20 @@ largest Emacs integer.") ;;; Parse a very simple number, keeping all digits. (defun math-read-number-simple (s) + "Convert the string S into a Calc number. +S is assumed to be a simple number (integer or float without an exponent) +and all digits are kept, regardless of Calc's current precision." (cond ;; Integer ((string-match "^[0-9]+$" s) - (cons 'bigpos (math-read-bignum s))) + (if (<= (length s) (* 2 math-bignum-digit-length)) + (string-to-number s) + (cons 'bigpos (math-read-bignum s)))) ;; Minus sign ((string-match "^-[0-9]+$" s) - (cons 'bigneg (math-read-bignum (substring s 1)))) + (if (<= (length s) (1+ (* 2 math-bignum-digit-length))) + (string-to-number s) + (cons 'bigneg (math-read-bignum (substring s 1))))) ;; Decimal point ((string-match "^\\(-?[0-9]*\\)\\.\\([0-9]*\\)$" s) (let ((int (math-match-substring s 1))